<?php use_helper('Object', 'Validation', 'ObjectAdmin', 'I18N', 'Date') ?>
<title><?= $sf_response->getTitle() ?></title>
<?php use_stylesheet('/sf/sf_admin/css/main') ?>

<div id="sf_admin_container">

<h1>View <?php echo $mr->getMrno() ?></h1>

<div id="sf_admin_content">


<fieldset id="sf_fieldset_none" class="">

<div class="form-row">
  <?php echo label_for('mr[mrno]', __($labels['mr{mrno}']), 'class="required" ') ?>
  <div class="content<?php if ($sf_request->hasError('mr{mrno}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr{mrno}')): ?>
    <?php echo form_error('mr{mrno}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <!--Tien-->
  <?php $default = CommonValues::GenerateAutoNumber('MR', $mr->getMrno(), 'MR')   ?>
   <input name="mr[mrno]" id="mr_mrno" value="<?php echo $default ?>"  type="hidden">
   <input name="mr_mrno_show" id="mr_mrno_show" value="<?php echo $default ?>" size="15" disabled="disabled" type="text">
   </div>
</div>

<div class="form-row">
  <?php echo label_for('mr[bom_id]', __($labels['mr{bom_id}']), 'class="required" ') ?>
  <div class="content<?php if ($sf_request->hasError('mr{bom_id}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr{bom_id}')): ?>
    <?php echo form_error('mr{bom_id}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php $value = object_select_tag($mr, 'getBomId', array (
  'related_class' => 'BOM',
  'control_name' => 'mr[bom_id]',
  'disabled'=>1,
)); echo $value ? $value : '&nbsp;' ?>
    </div>
</div>


<div class="form-row">
  <?php echo label_for('mr[reqarrdate]', __($labels['mr{reqarrdate}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('mr{reqarrdate}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr{reqarrdate}')): ?>
    <?php echo form_error('mr{reqarrdate}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php $value = object_input_date_tag($mr, 'getReqarrdate', array (
  'rich' => true,
  'calendar_button_img' => '/sf/sf_admin/images/date.png',
  'control_name' => 'mr[reqarrdate]',
  'disabled'=>1,
)); echo $value ? $value : '&nbsp;' ?>
    </div>
</div>

<div class="form-row">
  <?php echo label_for('mr[category]', __($labels['mr{category}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('mr{category}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr{category}')): ?>
    <?php echo form_error('mr{category}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>
     
    <select name="mr[category]" id="mr_category" disabled>
    <?php foreach (CommonValues::$gMRCategory['key'] as $key=>$category) { ?>
    <option value="<?php echo $category;  if ($category == $mr->getCategory()) echo '" selected="1'?>"><?php echo $key ?></option>
    <?php } ?>
    </select>
    </div>
</div>

<div class="form-row">
  <?php echo label_for('mr[status]', __($labels['mr{status}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('mr{status}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr{status}')): ?>
    <?php echo form_error('mr{status}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>
    <?php  $status = $mr->getStatus()?  $mr->getStatus(): 0?> 
  <input type="text" name ="mr_show" id ="mr_show" disabled="1"  value="<?php echo CommonValues::$gMRStatus['value'][$status]?>">
  <input type="hidden" name ="mr[status]" id ="mr_status" value="<?php echo $status?>">
    </div>
</div>

<div class="form-row">
  <?php echo label_for('mr[approvalstatus]', __($labels['mr{approvalstatus}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('mr{approvalstatus}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('mr{approvalstatus}')): ?>
    <?php echo form_error('mr{approvalstatus}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php  $status = $mr->getApprovalstatus()?  $mr->getApprovalstatus(): 0?> 
  <input type="text" name ="mr_show" id ="mr_show" disabled="1"  value="<?php echo CommonValues::$gMRApprovalStatus['value'][$status]?>">
  <input type="hidden" name ="mr[approvalstatus]" id ="mr_approvalstatus" value="<?php echo $status?>">
    </div>
</div>

</fieldset>

<!--Tien code here
get information for MR-->
<?php
    if ($mr->getComponentgroupId()){
        $componentGroupId = $mr->getComponentgroupId();
        
        $c = new Criteria();
        $c->add(ComponentsPeer::COMPONENTGROUP_ID , $componentGroupId);
        $c->addAscendingOrderByColumn(ComponentsPeer::ID);
        
        $componentList = ComponentsPeer::doSelect($c);
    }
?>


<?php 
echo link_to_remote('', array('update' => 'list_component', 
  'url' => 'component/listAjax', 
  'loading' => visual_effect('appear', 'indicator'),
  'complete' => visual_effect('fade', 'indicator'). visual_effect('highlight', 'list_component'),
  'position' => 'bottom',
));
?>

<table id ='added_components' "cellspacing="0" class="sf_admin_list">
<thead>
<tr>
      <th id="sf_admin_list_th_productcode" width="25%">Product Code
              </th>
      <th id="sf_admin_list_th_description" width="45%">Description
              </th>
      <th id="sf_admin_list_th_description" width="10%">Brand
              </th>       
      <th id="sf_admin_list_th_description" width="5%">Unit
              </th>
      <th id="sf_admin_list_th_description" width="10%">Expected Delivery Date (YYYY-MM-DD)</th>
      
      <th id="sf_admin_list_th_description">Qty to request</th>
</tr>
</thead>
<?
if (isset($componentList) && $componentList) {
    foreach ($componentList as $key=>$components) { 
        $component1= ComponentPeer::retrieveByPK($components->getComponentId());?>
        <tr class="sf_admin_row_<?php echo $key%2?>">
            <input type="hidden" name="rowIds[]" id ="rowIds"  class = "ExistComponents" value="<? echo $component1->getId()?>"/>
            <td><?echo $component1->getProductcode()?></td>
            <td><?echo $component1->getDescription()?></td>
            <td><?echo $component1->getBrand()?></td>
            <td><?echo $component1->getComponentunit()?></td>
            <td><?echo $components->getDate()?></td>
            <td><input type="text" name="qtys[]" id ="qtys" size="5" disabled value ="<?echo $components->getQty1()?>"></td>
        </tr>
<?php } }?>
</table>

</div>

</div>
